package userinterface;

import java.awt.Label;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.List;

import javax.swing.JOptionPane;

import alList.Lesson;
import excel.FormImport;

public class AddClaInfo extends AddInfo {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2L;

	public AddClaInfo() {
		super("AddClaInfo");
		
		ok.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				url = textField.getText();
				try {
					List<Lesson> classList = FormImport.readClaInfo(url);
					addDetail();
					
					previewButton.addMouseListener(new MouseAdapter() {
						@Override
						public void mouseClicked(MouseEvent e) {
							Preview.previewCla(classList);
						}
					});
					
					addButton.addMouseListener(new MouseAdapter() {
						@Override
						public void mouseClicked(MouseEvent e) {
							try {
								dBadd.addClaInfo(classList);
								Label label = new Label("Successfully add to Database!");
								container.add(label);
								label.setBounds(200, 230, 200, 30);
							} catch (SQLException e1) {
								e1.printStackTrace();
							}
						}
					});					
				} catch (Exception e1) {
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null, "Invalid url or file!");
				}

			};
		}
		);
	}
}